package com.example.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.project.entity.ConFiles;
import com.example.project.entity.NconMaterial;
import com.example.project.entity.Project;
import com.example.project.entity.User;
import com.example.project.mapper.ConFilesMapper;
import com.example.project.mapper.NconMaterialMapper;
import com.example.project.mapper.ProjectMapper;
import com.example.project.mapper.UserMapper;
import com.example.project.service.EchartsService;
import com.example.project.vo.model.echarts.Biscuits;
import com.example.project.vo.model.echarts.Pillar;
import com.example.project.vo.model.echarts.ScoreRank;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EchartsServiceImpl implements EchartsService {
    @Resource
    private ProjectMapper projectMapper;

    @Resource
    private NconMaterialMapper nconMaterialMapper;

    @Resource
    private ConFilesMapper conFilesMapper;

    @Resource
    private UserMapper userMapper;


    @Override
    public Map<String, Object> getAllData() {

        Map<String, Object> map = new HashMap<>();
        // 计算全部的数量

        Long count1 = projectMapper.selectCount(new LambdaQueryWrapper<Project>().eq(Project::getProjStatus, 0));
        Long count2 = nconMaterialMapper.selectCount(null);
        Long count3 = conFilesMapper.selectCount(null);
        Long count4 = projectMapper.selectCount(null);
        map.put("count1", count1);
        map.put("count2", count2);
        map.put("count3", count3);
        map.put("count4", count4);
//
//
//        // 计算饼图
        List<Biscuits> table1 = projectMapper.table1();
        table1.forEach(biscuits -> {
            String name = biscuits.getName();
            if ("1".equals(name)) {
                biscuits.setName("完成");
            } else {
                biscuits.setName("进行中");
            }
        });
        List<ScoreRank> table2 = projectMapper.table2();


        map.put("table1", table1);
        map.put("table2", table2);


        List<Biscuits> table3 = projectMapper.table3();
        table3.forEach(biscuits -> {
            String name = biscuits.getName();
            if ("1".equals(name)) {
                biscuits.setName("审批中");
            } else if ("2".equals(name)) {
                biscuits.setName("拒绝");
            } else {
                biscuits.setName("通过");
            }
        });

//
        // 计算柱状图
//        List<Biscuits> mattingBiscuits = projectMapper.table4();
//        Pillar pillar = Pillar.covertToP(mattingBiscuits);
//
//        map.put("table4",pillar);
        map.put("table3", table3);

        return map;
    }
}
